//
//  UITableView+PYCustom.m
//  IHome
//
//  Created by Jim on 2019/4/6.
//  Copyright © 2019 com.zhujizheng. All rights reserved.
//

#import "UITableView+PYCustom.h"

@implementation UITableView (PYCustom)

- (void)makeDefaultStyle
{
    if (@available(iOS 9.0, *)) {
        self.cellLayoutMarginsFollowReadableWidth = NO;
    }
    self.backgroundColor = PY_APP_ImageView_backgroundColor;
    self.separatorColor = PY_APP_TableView_separatorColor;
    
    self.sectionIndexColor = PY_Dark_Color;
    self.sectionIndexBackgroundColor = [UIColor clearColor];
    self.sectionIndexTrackingBackgroundColor = [UIColor clearColor];
    
    if (@available(iOS 11.0, *)) {
        self.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
}

- (UIImage*)getCaptureImage
{
    UIImage* viewImage = nil;
    UIGraphicsBeginImageContextWithOptions(self.contentSize, self.opaque, 0.0);
    {
        CGPoint savedContentOffset = self.contentOffset;
        CGRect savedFrame = self.frame;
        
        self.contentOffset = CGPointZero;
        self.frame = CGRectMake(0, 0, self.contentSize.width, self.contentSize.height);
        
        [self.layer renderInContext: UIGraphicsGetCurrentContext()];
        viewImage = UIGraphicsGetImageFromCurrentImageContext();
        
        self.contentOffset = savedContentOffset;
        self.frame = savedFrame;
    }
    UIGraphicsEndImageContext();
    
    return viewImage;
}

@end
